package com.kuangstudy.exresult;

import com.kuangstudy.exresult.ex.BussinessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * Description:
 * Author: yykk Administrator
 * Version: 1.0
 * Create Date Time: 2021/12/15 21:47.
 * Update Date Time:
 *
 * @see
 */
@Controller
public class TestErrorHandlerController {

    @GetMapping("/index")
    public String index() {
        return "/index";
    }


    // 数据库错误
    @GetMapping("/db")
    public String db() throws SQLException {
        if (true) {
            throw new SQLException("数据库出错了!!!");
        }
        return "/db";
    }

    // 自定义异常处理
    @GetMapping("/my")
    public String my() {
        if (true) {
            throw new BussinessException(501,"订单自定义异常!!!");
        }
        return "/db";
    }


    // 未知异常 -- 程序出现问题
    @GetMapping("/no")
    public String no() throws Exception {
        if (true) {
            throw new Exception("你出错了未知错误!!!");
        }
        return "/db";
    }

    @GetMapping("/hello")
    @ResponseBody
    public String suces(){
        return "wqdqwdqwdqw";
    }



}
